package com.hwh.controller;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import JDBCUtil.UTIL;

public class BuyGoodController extends HttpServlet{
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
	         throws ServletException, IOException {
      super.doPost(req, resp);
  }

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		PreparedStatement pst = null;
		Connection con = UTIL.getConn();

		ResultSet rs = null;
		StringBuffer sql = new StringBuffer("insert into orders values('',4,?,?,?,?)");
		try {
			pst = con.prepareStatement(sql.toString());
			// 返回一个结果集
			pst.setInt(1, 1);
			pst.setInt(2, 2);
			pst.setInt(3, 120);
			pst.setString(4, "大连市中软国际");
			pst.executeUpdate();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				UTIL.closeConn(rs, pst, con);
			} catch (SQLException e) {

				e.printStackTrace();
			}
		}
		
		req.getRequestDispatcher("buyindex.jsp").forward(req, resp);
		
		
		
	}
}
